package com.game.web.controller.game;

import com.game.common.annotation.Log;
import com.game.common.core.controller.BaseController;
import com.game.common.core.domain.AjaxResult;
import com.game.common.core.page.TableDataInfo;
import com.game.common.enums.BusinessType;
import com.game.common.utils.poi.ExcelUtil;
import com.game.common.utils.uuid.IdUtils;
import com.game.system.domain.game.GameDevice;
import com.game.system.service.IGameDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 游戏设备Controller
 *
 * @author Mr.Liu
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/game/device")
public class GameDeviceController extends BaseController
{
    @Autowired
    private IGameDeviceService gameDeviceService;

    /**
     * 查询游戏设备列表
     */
    @PreAuthorize("@ss.hasPermi('game:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(GameDevice gameDevice)
    {
        startPage();
        gameDevice.setUserId(getUserId());
        List<GameDevice> list = gameDeviceService.selectGameDeviceList(gameDevice);
        return getDataTable(list);
    }

    /**
     * 导出游戏设备列表
     */
    @PreAuthorize("@ss.hasPermi('game:device:export')")
    @Log(title = "游戏设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GameDevice gameDevice)
    {
        List<GameDevice> list = gameDeviceService.selectGameDeviceList(gameDevice);
        ExcelUtil<GameDevice> util = new ExcelUtil<GameDevice>(GameDevice.class);

        util.exportExcel(response, list, "游戏设备数据");
    }

    /**
     * 获取游戏设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('game:device:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(gameDeviceService.selectGameDeviceById(id));
    }

    /**
     * 新增游戏设备
     */
    @PreAuthorize("@ss.hasPermi('game:device:add')")
    @Log(title = "游戏设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GameDevice gameDevice)
    {
        gameDevice.setUserId(getUserId());
        gameDevice.setId(IdUtils.generateShortUUID());
        return toAjax(gameDeviceService.insertGameDevice(gameDevice));
    }


    /**
     * 修改游戏设备
     */
    @PreAuthorize("@ss.hasPermi('game:device:edit')")
    @Log(title = "游戏设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GameDevice gameDevice)
    {
        return toAjax(gameDeviceService.updateGameDevice(gameDevice));
    }

    /**
     * 删除游戏设备
     */
    @PreAuthorize("@ss.hasPermi('game:device:remove')")
    @Log(title = "游戏设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(gameDeviceService.deleteGameDeviceByIds(ids));
    }
}
